package com.bolt.support.desensitization.support;

import com.bolt.support.desensitization.annotation.ChineseNameSensitive;
import com.bolt.support.desensitization.desensitizer.*;
import com.bolt.support.enumtype.EnumKeyLabelPair;

import java.lang.annotation.Annotation;

public enum SensitiveType implements EnumKeyLabelPair {
    CHINESENAME(ChineseNameDesensitizer.class, 1, 0, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "中文名称";
        }
    },
    EMAIL(EmailDesensitizer.class, 0, 0, "(?<=.).*(?=@)", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "邮件";
        }
    },
    IDCARD(IdCardNumberDesensitizer.class, 6, 4, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "身份证号";
        }
    },
    PASSWORD(PasswordDesensitizer.class, 0, 0, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "密码";
        }
    },
    PHONENUMBER(PhoneNumberDesensitizer.class, 3, 4, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "手机号码";
        }
    },
    USCC(UsccDesensitizer.class, 2, 2, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "统一社会信用代码";
        }
    },

    BANKCARDNUM(BankCardNumberDesensitizer.class, 0, 4, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "银行卡号码";
        }
    },

    IGNORE(null, 0, 0, "", '*', null) {
        @Override
        public String getLabel() {
            return "忽略";
        }
    },

    CHARSEQUENCE(StringDesensitizer.class, 0, 0, "", '*', ChineseNameSensitive.AlwaysTrue.class) {
        @Override
        public String getLabel() {
            return "自定义";
        }
    };


    private Class<? extends Desensitizer<? extends CharSequence, ? extends Annotation>> desensitizer;


    private int startOffset;

    private int endOffset;

    private String regexp;

    private char placeholder;

    private Class<? extends Condition<? extends CharSequence>> condition;


    SensitiveType(Class<? extends Desensitizer<? extends CharSequence, ? extends Annotation>> desensitizer, int startOffset, int endOffset, String regexp, char placeholder, Class<? extends Condition<? extends CharSequence>> condition) {
        this.desensitizer = desensitizer;
        this.startOffset = startOffset;
        this.endOffset = endOffset;
        this.regexp = regexp;
        this.placeholder = placeholder;
        this.condition = condition;
    }

    public Class<? extends Desensitizer<? extends CharSequence, ? extends Annotation>> getDesensitizer() {
        return desensitizer;
    }

    public void setDesensitizer(Class<? extends Desensitizer<? extends CharSequence, ? extends Annotation>> desensitizer) {
        this.desensitizer = desensitizer;
    }

    public int getStartOffset() {
        return startOffset;
    }

    public void setStartOffset(int startOffset) {
        this.startOffset = startOffset;
    }

    public int getEndOffset() {
        return endOffset;
    }

    public void setEndOffset(int endOffset) {
        this.endOffset = endOffset;
    }

    public String getRegexp() {
        return regexp;
    }

    public void setRegexp(String regexp) {
        this.regexp = regexp;
    }

    public char getPlaceholder() {
        return placeholder;
    }

    public void setPlaceholder(char placeholder) {
        this.placeholder = placeholder;
    }

    public Class<? extends Condition<? extends CharSequence>> getCondition() {
        return condition;
    }

    public void setCondition(Class<? extends Condition<? extends CharSequence>> condition) {
        this.condition = condition;
    }
}